<?php
/**
 * @var $model Song
 * @var $this SongController
 */

Yii::import('application.components.GuitarTabs');
$this->breadcrumbs = array(
    'Bản nhạc' => array('song/index'),
    $model->title,
);
$this->pageTitle = $model->title;
?>
<div class="left">
    <?php if ($model->is_validated == 1): ?>
    <div id="list-training">

        <h1 class="title"><?php echo $model->title; ?></h1>
        <abbr class="date">Đăng bởi <span
            style="color: red;font-weight: bold;"><?php echo $model->user->username ?></span>
            vào lúc: <?php echo date('H:i', $model->create_time); ?>
            ngày  <?php echo date('d/m/Y', $model->create_time); ?>
        </abbr>
        <?php if ($model->embed_code): ?>
        <div style="margin: 10px 0px">
            <?php echo $model->embed_code; ?>
        </div>
        <?php endif; ?>
        <div id="rate" style="margin-top: 10px;">

            <?php echo CHtml::beginForm(); ?>
            <span id="star">
        <?php for ($i = 1; $i <= $model->star; $i++): ?>
                <img src="<?php echo Yii::app()->baseUrl; ?>/images/star.png">
                <?php endfor; ?>
            </span>
       <span id="av">
        <?php
           if ($model->rateCount > 0) {
               echo '<b>(' . $model->averrate . ', ' . $model->rateCount . ' votes)</b>';
           }
           ?>
           </span>
            <?php echo CHtml::listBox('marks', 0, array(0 => 'Điểm', 1 => '1 - Tồi', 2, 3, 4, 5 => '5 - TB', 6, 7, 8, 9, 10 => '10 - Tốt'), array('size' => 1)); ?>
            <?php echo CHtml::ajaxSubmitButton('Đánh giá', $this->createUrl('rate', array('id' => $model->id)), array('success' => 'js: function(data) {
                        if(data){
                            //var obj = JSON.parse(data);
                            if(data.login == 1){
                                alert("Bạn cần phải đăng nhập.");
                            }
                            if(data.success == 1){
                                window.location.reload();
                            }
                        }

                    }')); ?>
            <?php echo CHtml::endForm();?>
        </div>
        <script>
            $(function () {
                $("#tabs").tabs();
            });
        </script>
        <div id="tabs" style="margin-top: 20px; ">
            <ul>
                <li><a href="#tabs-1">Lời bài hát</a></li>
                <?php if ($model->guitar_tabs): ?>
                <li><a href="#tabs-2">Guitar Tabs</a></li>
                <?php endif; ?>
            </ul>
            <div id="tabs-1" class="song-body" style="margin-top: 5px;">
                <?php
                $l = new GuitarTabs();
                $l->add_section('', $model->body);
                $l->print_fixed2();
                ?>
            </div>
            <?php if ($model->guitar_tabs): ?>
             <div id='tabs-2'><pre><?php echo $model->guitar_tabs?></pre></div>;
            <?php endif; ?>
        </div>


        <div style="margin: 10px 0px;">
            <!-- AddThis Button BEGIN -->
            <div class="addthis_toolbox addthis_default_style ">
                <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
                <a class="addthis_button_tweet"></a>
                <a class="addthis_button_google_plusone" g:plusone:size="medium"></a>
                <a class="addthis_counter addthis_pill_style"></a>
            </div>
            <script type="text/javascript">//var addthis_config = {"data_track_addressbar":true};</script>
            <script type="text/javascript"
                    src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4f88f64654f5680c"></script>
            <!-- AddThis Button END -->
        </div>
        <?php
        //$this->renderPartial('_other_training', array('dataProvider' => $model->getOthers()));
        ?>
        <div id="comments">
            <?php if ($model->commentCount >= 1): ?>
            <h2>
                <?php echo $model->commentCount . ' Comments'; ?>
            </h2>

            <?php $this->renderPartial('_comments', array(
                'news' => $model,
                'comments' => $model->comments,
            )); ?>
            <?php endif; ?>

            <?php if (Yii::app()->user->checkAccess('comment')): ?>
            <h3 style="margin-top: 1em;b">Gửi bình luận</h3>

            <?php if (Yii::app()->user->hasFlash('commentSubmitted')): ?>
                <div class="flash-success">
                    <?php echo Yii::app()->user->getFlash('commentSubmitted'); ?>
                </div>
                <?php else: ?>
                <?php $this->renderPartial('/comment/_form', array(
                    'model' => $comment,
                )); ?>
                <?php endif; ?>
            <?php else: ?>
            <div> <?php echo CHtml::link('Đăng nhập', $this->createUrl('/site/login')); ?> để đăng bình luận.</div>
            <?php endif; ?>
            <div style="border-top: 1px solid #ccc">
                <h2 style="padding: 5px">Bình luận từ Facebook</h2>
                <div class="fb-comments" data-href="http://hocgioi.com.vn/lnt" data-num-posts="2" data-width="470"></div>
            </div>
        </div>
        <!-- comments -->

    </div>
    <?php else: ?>
    <div class="form">
        <div class="errorSummary">Bản nhạc đang chờ kiểm duyệt</div>
    </div>
    <?php endif; ?>
</div>
<div class="right">
    <?php
    $this->beginWidget('zii.widgets.CPortlet', array('title' => 'Cơ sở đào tạo'));
    $this->widget('FacilityList');
    $this->endWidget();
    ?>
</div>
<input type="hidden" id="dataurl" value="<?php echo $this->getAssetsUrl() . '/chords/'; ?>">

<script type="text/javascript">
    $(function () {
        //Template
        //	fr:freth
        // capo: [fret, length]
        // Finger : [string, pos]
        // String : 0 = normal string
        //			1 = bass string
        //			-1 = mute string
//        var chordsList = ["C", "Dm", "F", "G", "Am", "Em", "G7"];
        var chordsList = <?php echo $l->objTabs(); ?>;
        var dataUrl = '<?php echo $this->getAssetsUrl() . '/chords/'; ?>';
        $(this).chordsLoad(chordsList, '<?php echo $this->getAssetsUrl() . '/chords/'; ?>');

        //$("#cont").transpose();


    });
</script>

